package com.dxt.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * topic模式
 */
@Component
public class TopicModeConfig {
    public static final String EXCHANGE = "topic_exchange";
    public static final String QUEUE1 = "topic_queue_one";
    public static final String ROUTING_KEY_QUEUE1 = "topic.*.one";
    public static final String QUEUE2 = "topic_queue_two";
    public static final String ROUTING_KEY_QUEUE2 = "topic.#";

    @Bean
    public TopicExchange topicModeExchange(){
        return new TopicExchange(TopicModeConfig.EXCHANGE);
    }
    @Bean
    public Queue topicModeQueueOne(){
        return new Queue(TopicModeConfig.QUEUE1);
    }
    @Bean
    public Binding topicModeBindingOne(){
        return BindingBuilder.bind(topicModeQueueOne()).to(topicModeExchange()).with(TopicModeConfig.ROUTING_KEY_QUEUE1);
    }

    @Bean
    public Queue topicModeQueueTwo(){
        return new Queue(TopicModeConfig.QUEUE2);
    }
    @Bean
    public Binding topicModeBindingTwo(){
        return BindingBuilder.bind(topicModeQueueTwo()).to(topicModeExchange()).with(TopicModeConfig.ROUTING_KEY_QUEUE2);
    }
}
